﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;

using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace Weazel.Math.Test
{
  [TestClass]
  public class TestUnsignedAddition
  {
		/**************************************************************************
		 * Addition (Unsigned)
		 **************************************************************************/
    [TestMethod]
    public void TestUnsignedAddition_1()
    {					
			Integer a = new Integer(8, 0, false);
			Integer b = new Integer(8, 0, false);
			Assert.AreEqual("0", (a + b).ToDecimalString());
		}

    [TestMethod]
    public void TestUnsignedAddition_2()
    {					
			Integer a = new Integer(8, 1, false);
			Integer b = new Integer(8, 0, false);
			Assert.AreEqual("1", (a + b).ToDecimalString());
		}

    [TestMethod]
    public void TestUnsignedAddition_3()
    {					
			Integer a = new Integer(8, 10, false);
			Integer b = new Integer(8, 100, false);
			Assert.AreEqual("110", (a + b).ToDecimalString());
		}

    [TestMethod]
    public void TestUnsignedAddition_4()
    {					
			Integer a = new Integer(32, "0xFFFFFFFF", false);
			Integer b = new Integer(2, 1, false);

      Assert.AreEqual(-1, (int)a.Content[0]);
      Assert.AreEqual(1, (int)b.Content[0]);

      Integer result = a + b;

      Assert.AreEqual(32, result.Width);
      Assert.AreEqual(0, (int)result.Content[0]);

      Assert.AreEqual("0", result.ToDecimalString());
		}

		[TestMethod]
    public void TestUnsignedAddition_5()
    {					
			Integer a = new Integer(8, 0xFE, false);
			Integer b = new Integer(8, 3, false);


			Assert.AreEqual("1", (a + b).ToDecimalString());
		}

    [TestMethod]
    public void TestUnsignedAddition_6()
    {
      Integer a = new Integer(96, 9, false);
      Integer b = new Integer(8, -10, true);

      Assert.AreEqual(96, (a + b).Width);
      Assert.AreEqual("ffffffffffffffffffffffff", (a + b).ToHexadecimalString());
    }

    [TestMethod]
    public void TestMultipleAddOperationsLoopWithOverflow()
    {
      Integer a = new Integer(3, 0, false);
      Integer b = new Integer(3, 1, false);

      for (int i = 0; i < 10; i++)
        Integer.Add(ref a, a, b);

      Assert.AreEqual("2", a.ToDecimalString());
    }
  }
}
